
*******************************************************************************************************
*******************************************************************************************************
*** Title: Improving Workplace Climate in Large Corporations: A Clustered Randomized Intervention
*** Authors: Sule Alan, Gozde Corekcioglu, Matthias Sutter

*** Notes: This do-file replicates the main results. 
*******************************************************************************************************
*******************************************************************************************************

global qje "~/Dropbox/RESEARCH/Corporate Culture/Final QJE Files/Data Files"
global path1 "~/Dropbox/Apps/Overleaf/Corporate Culture RCT/figures"
global path2 "~/Dropbox/Apps/Overleaf/Corporate Culture RCT/tables"

use "$qje/AlanCorekciogluSutter_final.dta", clear  

*Define controls
global covar1 ravenscore eyescore agenew malenew married kids ldsize lesize dmaleshare tenure_yr_end
global covar2 malenew lesize ldsize dmaleshare
global covar3 lesize dmaleshare ldsize 


********************************************************************************
*Table 1: Endline Summary Statistics by Sector
********************************************************************************

global ind_vars malenew agenew married tenure_yr_end ///
					ravenscore eyescore ///
					sabotage_end trust_sent_end recipfrac ultim_offer_end ultim_min_accepted_end ///
					wsatis merit deptcoop desnorm presnorm ///
					leaderq leaderp leader_nominated_help_end leader_nominated_pers_end

clear matrix				
local count: word count $ind_vars

forval i=1/6 {

mat r`i'=J(1,`count',.)

	local j=1
	foreach var in $ind_vars {
		sum `var' if part==1 & sectorid==`i'
		mat r`i'[1,`j'] = r(mean)	
		loc j=`j'+1
	}

mat list r`i'
estadd matrix r`i', replace
	
}


local count: word count $ind_vars

local k=7

forval i=1/6 {

mat r`k'=J(1,`count',.)

	local j=1
	foreach var in $ind_vars {
		sum `var' if part==1 & sectorid==`i'
		mat r`k'[1,`j'] = r(sd)	
		loc j=`j'+1
	}

mat list r`k'
estadd matrix r`k', replace
		
loc k=`k'+1

}

#delimit ;
esttab using "$path2/Table1.tex", replace fragment
cells("r1(fmt(%8.3f)) r2(fmt(%8.3f)) r3(fmt(%8.3f)) r4(fmt(%8.3f)) r5(fmt(%8.3f)) r6(fmt(%8.3f))" 
"r7(par) r8(par) r9(par) r10(par) r11(par) r12(par)") 
noobs nonumbers nogaps
mlabels(, none) 
collabels("Chemicals" "Construction" "Defense" "Energy" "Finance" "Textile" )
coeflabels(c1 "Male" c2 "Age" c3 "Married" c4 "Tenure (years)" c5 "Raven's Score (IQ)" c6 "Eyes Score (Emotional Intelligence)" c7 "Sabotage" c8 "Trust" c9 "Reciprocity" c10 "Ultimatum Offer" c11 "Min. Accepted" c12 "Workplace Satisfaction" c13 "Meritocratic Values" c14 "Collegial Department" c15 "Behavioral Norms" c16 "Prescriptive Norms" c17 "Leader Professionalism" c18 "Leader Empathy" c19 "Nominated Leader as Professional Help" c20 "Nominated Leader as Personal Help" )
prehead("\hfill \\ \textbf{Panel I: Individual Characteristics}") 
;
#delimit cr

	* add sample sizes
	
local k=21

forval i=1/6 {

mat r`k'=J(1,1,.)

local j=1
sum id if part==1 & sectorid==`i'
mat r`k'[1,1] = r(N)	
loc j=`j'+1

mat list r`k'
estadd matrix r`k', replace
		
loc k=`k'+1

}

#delimit ;
esttab using "$path2/Table1.tex", append fragment
cells("r21(fmt(%8.0g)) r22(fmt(%8.0g)) r23(fmt(%8.0g)) r24(fmt(%8.0g)) r25(fmt(%8.0g)) r26(fmt(%8.0g))") 
noobs nonumbers nogaps
mlabels(, none) 
collabels(, none)
coeflabels(c1 "N" )
;
#delimit cr

	** Department characteristics

clear matrix 

preserve

keep if part== 1 & deptid~=. 

global dept_vars ldsize dmaleshare sep_imp sep_post 
	
collapse $dept_vars , by(deptid treat firmid sectorid)
						
sum $dept_vars	

local count: word count $dept_vars

forval i=1/6 {

mat r`i'=J(1,`count',.)

	local j=1
	foreach var in $dept_vars {
		sum `var' if sectorid==`i'
		mat r`i'[1,`j'] = r(mean)	
		loc j=`j'+1
	}

mat list r`i'
estadd matrix r`i', replace
	
}


local count: word count $dept_vars

local k=7

forval i=1/6 {

mat r`k'=J(1,`count',.)

	local j=1
	foreach var in $dept_vars {
		sum `var' if sectorid==`i'
		mat r`k'[1,`j'] = r(sd)	
		loc j=`j'+1
	}

mat list r`k'
estadd matrix r`k', replace
		
loc k=`k'+1

}

#delimit ;
esttab using "$path2/Table1.tex", append fragment
cells("r1(fmt(%8.3f)) r2(fmt(%8.3f)) r3(fmt(%8.3f)) r4(fmt(%8.3f)) r5(fmt(%8.3f)) r6(fmt(%8.3f))" 
"r7(par) r8(par) r9(par) r10(par) r11(par) r12(par)") 
noobs nonumbers nogaps
mlabels(, none) 
collabels("" "" "" "" "" "" )
coeflabels(c1 "Log Department Size" c2 "Male Share" c3 "Separation (Implementation)" c4 "Separation (Post-decree)")
prehead("\hfill \\ \textbf{Panel II: Department Characteristics}") 
;
#delimit cr	
	
	* add sample sizes
	
clear matrix 
	
local k=13

forval i=1/6 {

mat r`k'=J(1,1,.)

local j=1
sum deptid if sectorid==`i'
mat r`k'[1,1] = r(N)	
loc j=`j'+1

mat list r`k'
estadd matrix r`k', replace
		
loc k=`k'+1

}

#delimit ;
esttab using "$path2/Table1.tex", append fragment
cells("r13(fmt(%8.0g)) r14(fmt(%8.0g)) r15(fmt(%8.0g)) r16(fmt(%8.0g)) r17(fmt(%8.0g)) r18(fmt(%8.0g))") 
noobs nonumbers nogaps
mlabels(, none) 
collabels(, none)
coeflabels(c1 "N" )
;
#delimit cr
	
restore

********************************************************************************
*Table 2: Baseline Balance with the Fall 2019 Baseline Sample
********************************************************************************

	** Individual characteristics

preserve

	keep if part_base==1 

	local ind_vars malenew agenew bmarried tenure_yr work7_age work7male work7_leader ///
						bravenscore beyescore risk_sd comp_decision cont_sd ///
						bwsatis_sd bdeptcoop_sd bmerit_sd bdesnorm_sd bpresnorm_sd ///
						bleaderq_sd leader_nominated_help leader_nominated_pers 
				   
	local count: word count `ind_vars'
	mat eb=J(1,`count',0)
	mat p=J(1,`count',0)
	mat se=J(1,`count',0)
	loc k=1
	foreach i in `ind_vars' { 
		reg `i' treat i.sectorid, cluster(firmid)
		mat eb[1,`k']=_b[treat]
		mat p[1,`k']=(2 * ttail(e(df_r), abs(_b[treat]/_se[treat])))
		loc k = `k'+1
	}

	matrix colnames eb = `ind_vars'
	matrix colname p = `ind_vars'

	estpost ttest `ind_vars', by(treat)

	estadd matrix eb
	estadd matrix p, replace
	estimates store balance1  

	# delimit ;
	esttab balance1 using "$path2/Table2.tex", 
	replace fragment noobs nonumbers 
	star(* 0.10 ** 0.05 *** 0.01)   
	cells("count(label(N)) mu_1(fmt(3) label(Control Mean)) mu_2(fmt(3) label(Treatment Mean)) eb(fmt(3) label(Difference (T-C))) p(fmt(3) label(P-value of Difference) star)") ///
	coeflabels(malenew "Male" agenew "Age" bmarried "Married" tenure_yr "Tenure (yearly)" 
			   work7_age "Leader Age" work7male "Under Male Leader" work7_leader "Holding Leadership Position"
			   bravenscore "Raven Score (IQ)" beyescore "Eyes Score (Emotional Intelligence)" 
			   risk_sd "Risk Attitude" comp_decision "Competitiveness" 
			   cont_sd "Cooperation" bwsatis_sd "Workplace Satisfaction"
			   bdeptcoop_sd "Collegial Department" bmerit_sd "Meritocratic Values" 
			   bdesnorm_sd "Behavioral Norms" bpresnorm_sd "Prescriptive Norms"  
			   bleaderq_sd "Leader Quality" leader_nominated_help "Nominated Leader as Professional Help"
			   leader_nominated_pers "Nominated Leader as Personal Help")   
	prehead("\hfill \\ \textbf{Panel I: Individual Characteristics}") 
	substitute(_ \_ \hfill "" )
	;
	# delimit cr 

restore

	** Department Characteristics

preserve

	keep if part_base== 1 

	local dept_vars lbdsize bdmaleshare bisolatedh bisolatedp dens_dep_help_2 dens_dep_pers_2 ///
					age_seg_dep_help age_seg_dep_pers turnover_2019 
	
	collapse `dept_vars', by(bdeptid treat firmid sectorid)

	local count: word count `dept_vars'
	mat eb=J(1,`count',0)
	mat p=J(1,`count',0)
	mat se=J(1,`count',0)
	loc k=1
	foreach i in `dept_vars' { 
		reg `i' treat i.sectorid, cluster(firmid)
		mat eb[1,`k']=_b[treat]
		mat p[1,`k']=(2 * ttail(e(df_r), abs(_b[treat]/_se[treat])))
		loc k = `k'+1
	}

	matrix colnames eb = `dept_vars'
	matrix colname p = `dept_vars'

	estpost ttest `dept_vars', by(treat)

	estadd matrix eb
	estadd matrix p, replace
	estimates store balance2

	# delimit ;
	esttab balance2 using "$path2//Table2.tex", 
	append fragment noobs nonumbers  ///
	star(* 0.10 ** 0.05 *** 0.01) ///   
	cells("count(label(\hfill)) mu_1(fmt(3) label(\hfill)) mu_2(fmt(3) label(\hfill)) eb(fmt(3) label(\hfill)) p(fmt(3) label(\hfill) star)") ///
	coeflabels(lbdsize "Log Department Size" bdmaleshare "Male Share"
			   bisolatedh "Proportion of Isolated Nodes (Professional Support)" bisolatedp "Proportion of Isolated Nodes (Personal Support)" 
			   dens_dep_help_2 "Density of the Department (Professional Support)"
			   dens_dep_pers_2 "Density of the Department (Personal Support)"
			   age_seg_dep_help "Cohort Segregation Coefficient (Professional Support)"
			   age_seg_dep_pers "Cohort Segregation Coefficient (Personal Support)"
			   turnover_2019 "Separation") 
	prehead("\hfill \\ \textbf{Panel II: Department Characteristics}") ///			
	substitute(_ \_ \hfill "")		   
	;
	# delimit cr 
	
restore

	** Firm Characteristics

preserve
												
	collapse lbsize treat sectorid, by(firmid)
	
	local firm_vars lbsize
	local count: word count `firm_vars'
	mat eb=J(1,`count',0)
	mat p=J(1,`count',0)
	mat se=J(1,`count',0)
	loc k=1
	foreach i in `firm_vars' { 
		reg `i' treat i.sectorid, r
		mat eb[1,`k']=_b[treat]
		mat p[1,`k']=(2 * ttail(e(df_r), abs(_b[treat]/_se[treat])))
		loc k = `k'+1
	}

	matrix colnames eb = `firm_vars'
	matrix colname p = `firm_vars'

	estpost ttest `firm_vars', by(treat)

	estadd matrix eb
	estadd matrix p, replace
	estimates store balance3


	# delimit ;
	esttab balance3 using "$path2/Table2.tex", 
	append fragment noobs nonumbers ///
	star(* 0.10 ** 0.05 *** 0.01) ///   
	cells("count(label(\hfill)) mu_1(fmt(3) label(\hfill)) mu_2(fmt(3) label(\hfill)) eb(fmt(3) label(\hfill)) p(fmt(3) label(\hfill) star)") ///
	coeflabels(lbsize "Log of Firm Size (Headquarters)")
	prehead("\hfill \\ \textbf{Panel III: Firm Characteristics}") ///			
	substitute(_ \_ \hfill "")			
	;
	# delimit cr 
	
restore	

********************************************************************************
*Table 3: Treatment Effects on Separations (implementation period)
********************************************************************************
 
	*implementation separation 
	
	** Full sample
	
estimates clear
	
reg sep_imp treat $covar1 i.sectorid if part==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sep_imp if treat==0 & part==1
estadd scalar cmean=r(mean),  : s1
estadd local control "All", :s1

reg sep_imp treat $covar3 i.sectorid if part==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum sep_imp if treat==0 & part==1
estadd scalar cmean=r(mean),  : s2
estadd local control "Partial", :s2

reg sep_imp treat i.sectorid if part==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum sep_imp if treat==0 & part==1
estadd scalar cmean=r(mean),  : s3
estadd local control "No", :s3

#delimit ;
esttab s1 s2 s3 using "$path2/Table3.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp cmean N control, fmt(%9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Control Mean" "N" "Covariates"))
/*nogaps*/ gaps
mtitles("(1)" "(2)" "(3)")
mgroups("Separation (Implementation)" , 				
	pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
; 
#delimit cr

	** Subordinates only

estimates clear

reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end==0, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sep_imp if treat==0 & part==1 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s1
estadd local control "All", :s1

reg sep_imp treat $covar3 i.sectorid if part==1 & work7_leader_end==0, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum sep_imp if treat==0 & part==1 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s2
estadd local control "Partial", :s2

reg sep_imp treat i.sectorid if part==1 & work7_leader_end==0, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum sep_imp if treat==0 & part==1 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s3
estadd local control "No", :s3

#delimit ;
esttab s1 s2 s3  using "$path2/Table3.tex", append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp cmean N control, fmt(%9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Control Mean" "N" "Covariates"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill")
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
; 
#delimit cr

	** Leaders only
	
estimates clear

reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sep_imp if treat==0 & part==1 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s1
estadd local control "All", :s1

quietly reg sep_imp treat $covar1 i.sectorid if work7_leader_end==0 & part==1
est store x1
quietly reg sep_imp treat $covar1 i.sectorid if work7_leader_end==1 & part==1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s1

reg sep_imp treat $covar3 i.sectorid if part==1 & work7_leader_end==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum sep_imp if treat==0 & part==1 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s2
estadd local control "Partial", :s2

quietly reg sep_imp treat $covar3 i.sectorid if work7_leader_end==0 & part==1
est store x3
quietly reg sep_imp treat $covar3 i.sectorid if work7_leader_end==1 & part==1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s2

reg sep_imp treat i.sectorid if part==1 & work7_leader_end==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum sep_imp if treat==0 & part==1 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s3
estadd local control "No", :s3

quietly reg sep_imp treat i.sectorid if work7_leader_end==0 & part==1
est store x5
quietly reg sep_imp treat i.sectorid if work7_leader_end==1 & part==1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s3

#delimit ;
esttab s1 s2 s3  using "$path2/Table3.tex", append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp su_chi cmean N control, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Subordinate = Leader" "Control Mean" "N" "Covariates"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel III: Leaders only}")
; 
#delimit cr


	** Non-participant sample
		
estimates clear

reg sep_imp treat $covar2 i.sectorid if part==0 , cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sep_imp if treat==0 & part==0 
estadd scalar cmean=r(mean),  : s1
estadd local control "All", :s1

reg sep_imp treat $covar3 i.sectorid if part==0 , cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum sep_imp if treat==0 & part==0 
estadd scalar cmean=r(mean),  : s2
estadd local control "Partial", :s2

reg sep_imp treat i.sectorid if part==0 , cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum sep_imp if treat==0 & part==0 
estadd scalar cmean=r(mean),  : s3
estadd local control "No", :s3

#delimit ;
esttab s1 s2 s3 using "$path2/Table3.tex", append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp cmean N control, fmt(%9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Control Mean" "N" "Covariates"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel IV: Non-participant sample}")
; 
#delimit cr
	
********************************************************************************
*Table 4: Treatment Effects on Incentivized Outcomes
********************************************************************************

	** Full sample

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1
	
foreach var in sabotage_end trust_sent_end recipfrac ultim_offer_end ultim_min_accepted_end {						
	reg `var' treat $covar1 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg sabotage_end treat $covar1  i.sectorid , cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sabotage_end if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg trust_sent_end treat $covar1 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum trust_sent_end if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg recipfrac treat $covar1 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum recipfrac if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3


reg ultim_offer_end treat $covar1 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum ultim_offer_end if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg ultim_min_accepted_end treat $covar1 i.sectorid, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum ultim_min_accepted_end if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5


#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table4.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Sabotage" "Trust" "Reciprocity" "Ultimatum Offer" "Min. Accepted")
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
;
#delimit cr

** 
	** Subordinates only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1
	
foreach var in sabotage_end trust_sent_end recipfrac ultim_offer_end ultim_min_accepted_end {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg sabotage_end treat $covar1  i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sabotage_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg trust_sent_end treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum trust_sent_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg recipfrac treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum recipfrac if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3


reg ultim_offer_end treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum ultim_offer_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg ultim_min_accepted_end treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum ultim_min_accepted_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table4.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
;
#delimit cr


** 
	** Leaders only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1
	
foreach var in sabotage_end trust_sent_end recipfrac ultim_offer_end ultim_min_accepted_end {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg sabotage_end treat $covar1  i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sabotage_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

quietly reg sabotage_end treat $covar1 i.sectorid if work7_leader_end==0
est store x1
quietly reg sabotage_end treat $covar1 i.sectorid if work7_leader_end==1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s1

reg trust_sent_end treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum trust_sent_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

quietly reg trust_sent_end treat $covar1 i.sectorid if work7_leader_end==0
est store x3
quietly reg trust_sent_end treat $covar1 i.sectorid if work7_leader_end==1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s2

reg recipfrac treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum recipfrac if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

quietly reg recipfrac treat $covar1 i.sectorid if work7_leader_end==0
est store x5
quietly reg recipfrac treat $covar1 i.sectorid if work7_leader_end==1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s3

reg ultim_offer_end treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum ultim_offer_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

quietly reg ultim_offer_end treat $covar1 i.sectorid if work7_leader_end==0
est store x7
quietly reg ultim_offer_end treat $covar1 i.sectorid if work7_leader_end==1
est store x8
suest x7 x8, cluster(firmid)
test [x7_mean]treat = [x8_mean]treat 
estadd scalar su_chi = r(p),  : s4

reg ultim_min_accepted_end treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum ultim_min_accepted_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

quietly reg ultim_min_accepted_end treat $covar1 i.sectorid if work7_leader_end==0
est store x9
quietly reg ultim_min_accepted_end treat $covar1 i.sectorid if work7_leader_end==1
est store x10
suest x9 x10, cluster(firmid)
test [x9_mean]treat = [x10_mean]treat 
estadd scalar su_chi = r(p),  : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table4.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval su_chi cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Subordinate = Leader" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel III: Leaders only}")
;
#delimit cr

********************************************************************************
*Table 5: Treatment Effects on Support Networks (Department-level analysis)
********************************************************************************

preserve

drop if deptid==. 

collapse isolated* dens_dep_* age_seg_dep_* ravenscore eyescore agenew malenew married tenure_yr_end kids ldsize dmaleshare treat firmid sectorid, by(deptid)

global covar4 ravenscore eyescore agenew married kids ldsize dmaleshare tenure_yr_end

	** Full sample
	
*Store matrix with sharpened q-values 

mat pvals_true=J(1,6,0)

mat list pvals_true

loc k=1

foreach var in isolated_help isolated_pers dens_dep_help_2_end dens_dep_pers_2_end age_seg_dep_help_end age_seg_dep_pers_end {						
	reg `var' treat $covar4 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

restore 

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

preserve

drop if deptid==. 

collapse isolated* dens_dep_* age_seg_dep_* ravenscore eyescore agenew malenew married tenure_yr_end kids ldsize dmaleshare treat firmid sectorid, by(deptid)

global covar4 ravenscore eyescore agenew married kids ldsize dmaleshare tenure_yr_end

reg isolated_help treat $covar4 i.sectorid, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum isolated_help if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg isolated_pers treat $covar4 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum isolated_pers if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg dens_dep_help_2_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum dens_dep_help_2_end if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg dens_dep_pers_2_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum dens_dep_pers_2_end if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg age_seg_dep_help_end treat $covar4 i.sectorid , cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum age_seg_dep_help_end if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

reg age_seg_dep_pers_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s6
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s6
sum age_seg_dep_pers_end if treat==0
estadd scalar cmean=r(mean),  : s6
mat list qval_index
scalar qval= qval_index[6,2]
di qval
estadd scalar qval, : s6

#delimit ;
esttab s1 s2 s3 s4 s5 s6 using "$path2/Table5.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Professional S." "Personal S." "Professional S." "Personal S." "Professional S." "Personal S.")
mgroups("Proportion Isolated" "Department Density" "Cohort Segregation" , 
		pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
substitute("&\multicolumn{2}{S}{" "\multicolumn{1}{c}{")
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ") 
;
#delimit cr

**

	**Subordinates Only

estimates clear

*Store matrix with sharpened q-values 

mat pvals_true=J(1,6,0)

mat list pvals_true

loc k=1

foreach var in isolated_help_s isolated_pers_s dens_dep_help_nl_2_end dens_dep_pers_nl_2_end age_seg_dep_help_nl_end age_seg_dep_pers_nl_end {						
	reg `var' treat $covar4 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

restore 

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

preserve

drop if deptid==. 

collapse isolated* dens_dep_* age_seg_dep_* ravenscore eyescore agenew malenew married tenure_yr_end kids ldsize dmaleshare treat firmid sectorid, by(deptid)

global covar4 ravenscore eyescore agenew married kids ldsize dmaleshare tenure_yr_end

reg isolated_help_s treat $covar4 i.sectorid, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum isolated_help_s if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg isolated_pers_s treat $covar4 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum isolated_pers_s if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg dens_dep_help_nl_2_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum dens_dep_help_nl_2_end if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg dens_dep_pers_nl_2_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum dens_dep_pers_nl_2_end if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg age_seg_dep_help_nl_end treat $covar4 i.sectorid , cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum age_seg_dep_help_nl_end if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

reg age_seg_dep_pers_nl_end treat $covar4 i.sectorid, cluster(firmid)
estimates store s6
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s6
sum age_seg_dep_pers_nl_end if treat==0
estadd scalar cmean=r(mean),  : s6
mat list qval_index
scalar qval= qval_index[6,2]
di qval
estadd scalar qval, : s6

#delimit ;
esttab s1 s2 s3 s4 s5 s6 using "$path2/Table5.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" "\hfill")
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
;
#delimit cr

eststo clear

restore 

********************************************************************************
*Table 6: Treatment Effects on Workplace Climate 
********************************************************************************

estimates clear 
 
	** Full sample

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in wsatis merit deptcoop desnorm presnorm {						
	reg `var' treat $covar1 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg wsatis treat $covar1  i.sectorid , cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum wsatis if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg merit treat $covar1 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum merit if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg deptcoop treat $covar1 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum deptcoop if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg desnorm treat $covar1 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum desnorm if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg presnorm treat $covar1 i.sectorid, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum presnorm if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5


#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table6.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Workplace S." "Meritocratic Values" "Collegial Dept." "Behavioral Norms" "Prescriptive Norms")
mgroups("Workplace Quality" "Relational Atmosphere", pattern(1 0 1 0 0) 
	prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
substitute("&\multicolumn{2}{S}{" "\multicolumn{1}{c}{")
;
#delimit cr

** 
	** Subordinates only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in wsatis merit deptcoop desnorm presnorm {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg wsatis treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum wsatis if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg merit treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum merit if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg deptcoop treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum deptcoop if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg desnorm treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum desnorm if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg presnorm treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum presnorm if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table6.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
;
#delimit cr

** 
	** Leaders only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in wsatis merit deptcoop desnorm presnorm {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg wsatis treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum wsatis if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1
quietly reg wsatis treat $covar1 i.sectorid if work7_leader_end == 0
est store x1
quietly reg wsatis treat $covar1 i.sectorid if work7_leader_end == 1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s1

reg merit treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum merit if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

quietly reg merit treat $covar1 i.sectorid if work7_leader_end == 0
est store x3
quietly reg merit treat $covar1 i.sectorid if work7_leader_end == 1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s2

reg deptcoop treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum deptcoop if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

quietly reg deptcoop treat $covar1 i.sectorid if work7_leader_end == 0
est store x5
quietly reg deptcoop treat $covar1 i.sectorid if work7_leader_end == 1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s3

reg desnorm treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum desnorm if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

quietly reg desnorm treat $covar1 i.sectorid if work7_leader_end == 0
est store x7
quietly reg desnorm treat $covar1 i.sectorid if work7_leader_end == 1
est store x8
suest x7 x8, cluster(firmid)
test [x7_mean]treat = [x8_mean]treat 
estadd scalar su_chi = r(p),  : s4

reg presnorm treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum presnorm if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

quietly reg presnorm treat $covar1 i.sectorid if work7_leader_end == 0
est store x9
quietly reg presnorm treat $covar1 i.sectorid if work7_leader_end == 1
est store x10
suest x9 x10, cluster(firmid)
test [x9_mean]treat = [x10_mean]treat 
estadd scalar su_chi = r(p),  : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table6.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval su_chi cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Subordinate = Leader" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel III: Leaders only}")
;
#delimit cr

********************************************************************************
*Table 7: Treatment Effects on Covid-related Well-being 
********************************************************************************

estimates clear 

	** Full sample

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in preferhome lonely notconnected_c notconnected_l vice {						
	reg `var' treat $covar1 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg preferhome treat $covar1 i.sectorid , cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum preferhome if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg lonely treat $covar1 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum lonely if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg notconnected_c treat $covar1 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum notconnected_c if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg notconnected_l treat $covar1 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum notconnected_l if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg vice treat $covar1 i.sectorid, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum vice if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5


#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table7.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Prefer to Work at Home" "Feel Lonely" "Not Connected to Colleagues" "Not Connected to Leader" "Increased Vice Consumption")
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
substitute("&\multicolumn{2}{S}{" "\multicolumn{1}{c}{")
;
#delimit cr

** 

	** Subordinates only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in  preferhome lonely notconnected_c notconnected_l vice {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg preferhome treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum preferhome if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg lonely treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum lonely if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg notconnected_c treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum notconnected_c if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg notconnected_l treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum notconnected_l if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg vice treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum vice if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table7.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
;
#delimit cr

** 
	** Leaders only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in  preferhome lonely notconnected_c notconnected_l vice {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true


* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg preferhome treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum preferhome if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

quietly reg preferhome treat $covar1 i.sectorid if work7_leader_end == 0
est store x1
quietly reg preferhome treat $covar1 i.sectorid if work7_leader_end == 1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s1

reg lonely treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum lonely if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

quietly reg lonely treat $covar1 i.sectorid if work7_leader_end == 0
est store x3
quietly reg lonely treat $covar1 i.sectorid if work7_leader_end == 1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s2

reg notconnected_c treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum notconnected_c if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

quietly reg notconnected_c treat $covar1 i.sectorid if work7_leader_end == 0
est store x5
quietly reg notconnected_c treat $covar1 i.sectorid if work7_leader_end == 1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s3

reg notconnected_l treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum notconnected_l if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

quietly reg notconnected_l treat $covar1 i.sectorid if work7_leader_end == 0
est store x7
quietly reg notconnected_l treat $covar1 i.sectorid if work7_leader_end == 1
est store x8
suest x7 x8, cluster(firmid)
test [x7_mean]treat = [x8_mean]treat 
estadd scalar su_chi = r(p),  : s4

reg vice treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum vice if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

quietly reg vice treat $covar1 i.sectorid if work7_leader_end == 0
est store x9
quietly reg vice treat $covar1 i.sectorid if work7_leader_end == 1
est store x10
suest x9 x10, cluster(firmid)
test [x9_mean]treat = [x10_mean]treat 
estadd scalar su_chi = r(p),  : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table7.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval su_chi cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Subordinate = Leader" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel III: Leaders only}")
;
#delimit cr

********************************************************************************
*Table 8: Treatment Effects on Summary Indices (with Multiple Hypothesis Testing) 
********************************************************************************

estimates clear 
	
	** Full sample

*Store matrix with sharpened q-values 
*use wild-strapped p-values to compute sharpened q-values

mat pvals_true=J(1,4,0)

mat list pvals_true

reg sep_imp treat $covar1 i.sectorid if part==1, cluster(firmid)
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
mat pvals_true[1,1]=r(p)
mat list pvals_true

loc k=2 

foreach var in expvars_norm surveyvars_norm leadervars_norm {						
	reg `var' treat $covar1 i.sectorid, cluster(firmid)
	boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
	mat pvals_true[1,`k']=r(p)
	local ++k
	}


mat colnames pvals_true= "Separation (implementation)" "Prosocial Behavior" "Workplace Climate" "Leadership Quality"	
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

reg sep_imp treat $covar1 i.sectorid if part==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum sep_imp if treat==0 & part==1
estadd scalar cmean=r(mean),  : s1
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_sep_imp)
estadd scalar rw, : s1
mat list qval_index
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg expvars_norm treat $covar1 i.sectorid , cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum expvars_norm if treat==0
estadd scalar cmean=r(mean),  : s2
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_expvars_norm)
estadd scalar rw, : s2
mat list qval_index
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg surveyvars_norm treat $covar1  i.sectorid , cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum surveyvars_norm if treat==0
estadd scalar cmean=r(mean),  : s3
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_surveyvars_norm)
estadd scalar rw, : s3
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg leadervars_norm treat $covar1  i.sectorid , cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum leadervars_norm if treat==0
estadd scalar cmean=r(mean),  : s4
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_leadervars_norm)
estadd scalar rw, : s4
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

#delimit ;
esttab s1 s2 s3 s4 using "$path2/Table8.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp rw qval cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value"  "Romano-Wolf P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Separation (Implementation)" "Prosocial Behavior" "Workplace Climate" "Leadership Quality")
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
; 
#delimit cr

**

	** Subordinates only

estimates clear

*Store matrix with sharpened q-values 
*use wild-strapped p-values to compute sharpened q-values
	
mat pvals_true=J(1,4,0)

mat list pvals_true
	
reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end == 0, cluster(firmid)
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
mat pvals_true[1,1]=r(p)
mat list pvals_true

loc k=2 

foreach var in expvars_norm surveyvars_norm leadervars_norm {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end == 0, cluster(firmid)
	boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
	mat pvals_true[1,`k']=r(p)
	local ++k
	}


mat colnames pvals_true= "Separation (implementation)" "Prosocial Behavior" "Workplace Climate" "Leadership Quality"	
mat list pvals_true


* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store matrix values as variable 
svmat pvals_true, name(pval)

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end == 0, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum sep_imp if treat==0 & part==1 & work7_leader_end == 0
estadd scalar cmean=r(mean),  : s5
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 0, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_sep_imp)
estadd scalar rw, : s5
mat list qval_index
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s5

reg expvars_norm treat $covar1 i.sectorid if work7_leader_end == 0, cluster(firmid)
estimates store s6
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s6
sum expvars_norm if treat==0 & work7_leader_end == 0
estadd scalar cmean=r(mean),  : s6
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 0, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_expvars_norm)
estadd scalar rw, : s6
mat list qval_index
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s6

reg surveyvars_norm treat $covar1 i.sectorid if work7_leader_end == 0, cluster(firmid)
estimates store s7
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s7
sum surveyvars_norm if treat==0 & work7_leader_end == 0
estadd scalar cmean=r(mean),  : s7
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 0, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_surveyvars_norm)
estadd scalar rw, : s7
mat list qval_index
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s7

reg leadervars_norm treat $covar1 i.sectorid if work7_leader_end == 0, cluster(firmid)
estimates store s8
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s8
sum leadervars_norm if treat==0 & work7_leader_end == 0
estadd scalar cmean=r(mean),  : s8
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 0, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_leadervars_norm)
estadd scalar rw, : s8
mat list qval_index
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s8
	
#delimit ;
esttab s5 s6 s7 s8 using "$path2/Table8.tex", append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp rw qval cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value"  "Romano-Wolf P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill")
prehead("\hfill \\\textbf{Panel II: Subordinates only}")
;
#delimit cr	

**


	** Leaders only

*Store matrix with sharpened q-values 
*use wild-strapped p-values to compute sharpened q-values
	
mat pvals_true=J(1,4,0)

mat list pvals_true
		

reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end == 1, cluster(firmid)
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
mat pvals_true[1,1]=r(p)
mat list pvals_true

loc k=2 

foreach var in expvars_norm surveyvars_norm leadervars_norm {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end == 1, cluster(firmid)
	boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
	mat pvals_true[1,`k']=r(p)
	local ++k
	}


mat colnames pvals_true= "Separation (implementation)" "Prosocial Behavior" "Workplace Climate" "Leadership Quality"	
mat list pvals_true


* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store matrix values as variable 
svmat pvals_true, name(pval)

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end == 1, cluster(firmid)
estimates store s9
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s9
sum sep_imp if treat==0 & part==1 & work7_leader_end == 1
estadd scalar cmean=r(mean),  : s9
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_sep_imp)
estadd scalar rw, : s9
mat list qval_index
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s9

quietly reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end==0
est store x1
quietly reg sep_imp treat $covar1 i.sectorid if part==1 & work7_leader_end==1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s9

reg expvars_norm treat $covar1  i.sectorid if work7_leader_end == 1, cluster(firmid)
estimates store s10
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s10
sum expvars_norm if treat==0 & work7_leader_end == 1
estadd scalar cmean=r(mean),  : s10
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_expvars_norm)
estadd scalar rw, : s10
mat list qval_index
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s10

quietly reg expvars_norm treat $covar1 i.sectorid if work7_leader_end==0
est store x3
quietly reg expvars_norm treat $covar1 i.sectorid if work7_leader_end==1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s10

reg surveyvars_norm treat $covar1  i.sectorid if work7_leader_end == 1, cluster(firmid)
estimates store s11
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s11
sum surveyvars_norm if treat==0 & work7_leader_end == 1
estadd scalar cmean=r(mean),  : s11
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_surveyvars_norm)
estadd scalar rw, : s11
mat list qval_index
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s11

quietly reg surveyvars_norm treat $covar1 i.sectorid if work7_leader_end==0
est store x5
quietly reg surveyvars_norm treat $covar1 i.sectorid if work7_leader_end==1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s11

reg leadervars_norm treat $covar1  i.sectorid if work7_leader_end == 1, cluster(firmid)
estimates store s12
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s12
sum leadervars_norm if treat==0 & work7_leader_end == 1
estadd scalar cmean=r(mean),  : s12
rwolf sep_imp expvars_norm surveyvars_norm leadervars_norm if part==1  & work7_leader_end == 1, indepvar(treat) controls( $covar1 i.sectorid) reps(500) cluster(firmid) seed(1234)
scalar define rw=e(rw_leadervars_norm)
estadd scalar rw, : s12
mat list qval_index
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s12

quietly reg leadervars_norm treat $covar1 i.sectorid if work7_leader_end==0
est store x7
quietly reg leadervars_norm treat $covar1 i.sectorid if work7_leader_end==1
est store x8
suest x7 x8, cluster(firmid)
test [x7_mean]treat = [x8_mean]treat 
estadd scalar su_chi = r(p),  : s12
 
#delimit ;
esttab s9 s10 s11 s12 using "$path2/Table8.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp rw qval su_chi cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value"  "Romano-Wolf P-value" "Sharpened q-value" "Subordinate = Leader" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\\textbf{Panel III: Leaders only} \\ ")
;
#delimit cr	 

********************************************************************************
*Table 9: Treatment Effects on Leadership Quality and Own Empathy
********************************************************************************

estimates clear 

	** Full sample

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in leaderq leaderp leader_nominated_help_end leader_nominated_pers_end perspective {						
	reg `var' treat $covar1 i.sectorid, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg leaderq treat $covar1 i.sectorid , cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum leaderq if treat==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg leaderp treat $covar1 i.sectorid, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum leaderp if treat==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg leader_nominated_help_end treat $covar1 i.sectorid, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum leader_nominated_help_end if treat==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg leader_nominated_pers_end treat $covar1 i.sectorid, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum leader_nominated_pers_end if treat==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg perspective treat $covar1 i.sectorid, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum perspective if treat==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5


#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table9.tex",  replace fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("Leader Professionalism" "Leader Empathy" "Professional Help from Leader" "Personal Help from Leader" "Own Empathy")
prehead("\hfill \\\textbf{Panel I: Full sample} \\ ")
substitute("&\multicolumn{2}{S}{" "\multicolumn{1}{c}{")
;
#delimit cr

** 

	** Subordinates only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in leaderq leaderp leader_nominated_help_end leader_nominated_pers_end perspective {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg leaderq treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum leaderq if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

reg leaderp treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum leaderp if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

reg leader_nominated_help_end treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum leader_nominated_help_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

reg leader_nominated_pers_end treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum leader_nominated_pers_end if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

reg perspective treat $covar1 i.sectorid if work7_leader_end==0, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum perspective if treat==0 & work7_leader_end==0
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table9.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval cmean N, fmt(%9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel II: Subordinates only}")
;
#delimit cr

** 
	** Leaders only

estimates clear 

*Store matrix with sharpened q-values 

mat pvals_true=J(1,5,0)

mat list pvals_true

loc k=1

foreach var in leaderq leaderp leader_nominated_help_end leader_nominated_pers_end perspective {						
	reg `var' treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
	mat result = r(table)
	mat pvals_true[1,`k']=result[4,1]
	local ++k
	}
		
mat list pvals_true

* To control FDR: paste true p-values into Michael Anderson do-file
mat pvals_true = pvals_true'
mat list pvals_true

*Run Anderson do-file
do "$qje/fdr_sharpened_qvalues.do"

*store results after running Anderson dofile for each outcome group
mkmat pval bky06_qval, matrix(qval_index)
mat list qval_index

*Load the original data back
do "$qje/AlanCorekciogluSutter_data.do"

**

reg leaderq treat $covar1  i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s1
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s1
sum leaderq if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s1
mat list qval_index 
scalar qval= qval_index[1,2]
di qval
estadd scalar qval, : s1

quietly reg leaderq treat  $covar1  i.sectorid if work7_leader_end == 0
est store x1
quietly reg leaderq treat  $covar1  i.sectorid if work7_leader_end == 1
est store x2
suest x1 x2, cluster(firmid)
test [x1_mean]treat = [x2_mean]treat 
estadd scalar su_chi = r(p),  : s1

reg leaderp treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s2
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s2
sum leaderp if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s2
mat list qval_index 
scalar qval= qval_index[2,2]
di qval
estadd scalar qval, : s2

quietly reg leaderp treat  $covar1  i.sectorid if work7_leader_end == 0
est store x3
quietly reg leaderp treat  $covar1  i.sectorid if work7_leader_end == 1
est store x4
suest x3 x4, cluster(firmid)
test [x3_mean]treat = [x4_mean]treat 
estadd scalar su_chi = r(p),  : s2

reg leader_nominated_help_end treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s3
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s3
sum leader_nominated_help_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s3
mat list qval_index 
scalar qval= qval_index[3,2]
di qval
estadd scalar qval, : s3

quietly reg leader_nominated_help_end treat  $covar1  i.sectorid if work7_leader_end == 0
est store x5
quietly reg leader_nominated_help_end treat  $covar1  i.sectorid if work7_leader_end == 1
est store x6
suest x5 x6, cluster(firmid)
test [x5_mean]treat = [x6_mean]treat 
estadd scalar su_chi = r(p),  : s3

reg leader_nominated_pers_end treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s4
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s4
sum leader_nominated_pers_end if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s4
mat list qval_index 
scalar qval= qval_index[4,2]
di qval
estadd scalar qval, : s4

quietly reg leader_nominated_pers_end treat  $covar1  i.sectorid if work7_leader_end == 0
est store x7
quietly reg leader_nominated_pers_end treat  $covar1  i.sectorid if work7_leader_end == 1
est store x8
suest x7 x8, cluster(firmid)
test [x7_mean]treat = [x8_mean]treat 
estadd scalar su_chi = r(p),  : s4

reg perspective treat $covar1 i.sectorid if work7_leader_end==1, cluster(firmid)
estimates store s5
boottest treat, reps(999) boottype(wild) small cluster(firmid) nogr seed(1)
estadd scalar bootp = r(p), : s5
sum perspective if treat==0 & work7_leader_end==1
estadd scalar cmean=r(mean),  : s5
mat list qval_index 
scalar qval= qval_index[5,2]
di qval
estadd scalar qval, : s5

quietly reg perspective treat  $covar1  i.sectorid if work7_leader_end == 0
est store x9
quietly reg perspective treat  $covar1  i.sectorid if work7_leader_end == 1
est store x10
suest x9 x10, cluster(firmid)
test [x9_mean]treat = [x10_mean]treat 
estadd scalar su_chi = r(p),  : s5

#delimit ;
esttab s1 s2 s3 s4 s5 using "$path2/Table9.tex",  append fragment label compress b(%8.3f) se(3) 
nonumbers keep(treat)
coeflabels( treat "Treatment" )
star(* 0.10 ** 0.05 *** 0.01) nonotes 
s(bootp qval su_chi cmean N, fmt(%9.3f %9.3f %9.3f %9.3f %9.0g) labels("Wild Bootstrap P-value" "Sharpened q-value" "Subordinate = Leader" "Control Mean" "N"))
/*nogaps*/ gaps
mtitles ("\hfill" "\hfill" "\hfill" "\hfill" "\hfill" )
prehead("\hfill \\ \textbf{Panel III: Leaders only}")
;
#delimit cr

********************************************************************************
*Figure 3: Monthly Separation Rates, weighted by Headquarters shares
********************************************************************************

preserve

collapse sep_imp esize bsize seprate_prepost* sep_prepost* size_prepost* treat sectorid, by(firmid)

reshape long seprate_prepost sep_prepost size_prepost, i(firmid) j(monyear)

gen monyear_str=string(monyear, "%tm")
labmask monyear, val(monyear_str)

gen bshare=bsize/size_prepost 
gen eshare=esize/size_prepost

gen share=. 
replace share=bshare if monyear<=729
replace share=eshare if monyear>729

format monyear %tm 

la var treat "Treatment"

xtset firmid monyear

**Panel B: coefficient plot (re-weighted)

estimates clear

loc i=1
forval t=696/707 {
	reg seprate_prepost treat i.sectorid if monyear==`t' [pw=1/share], r  
	est sto m1`i'
        *build macro for coefplot
        loc cc `"`cc' (m1`i', aseq("2018m`i'")) "'
    loc `++i'		
}
di `"`cc'"'


loc i=1
forval t=708/719 {
	reg seprate_prepost treat i.sectorid if monyear==`t' [pw=1/share], r 
	est sto m2`i'
        *build macro for coefplot
        loc ccc `"`ccc' (m2`i', aseq("2019m`i'")) "'
    loc `++i'		
}
di `"`ccc'"'

loc i=1
forval t=720/731 {
	reg seprate_prepost treat i.sectorid if monyear==`t' [pw=1/share], r
	est sto m3`i'
        *build macro for coefplot
        loc cccc `"`cccc' (m3`i', aseq("2020m`i'")) "'
    loc `++i'		
}
di `"`cccc'"'

loc i=1
forval t=732/743 {
	reg seprate_prepost treat i.sectorid if monyear==`t' [pw=1/share], r
	est sto m4`i'
        *build macro for coefplot
        loc ccccc `"`ccccc' (m4`i', aseq("2021m`i'")) "'
    loc `++i'		
}
di `"`ccccc'"'

loc i=1
forval t=744/746 {
	reg seprate_prepost treat i.sectorid if monyear==`t' [pw=1/share], r
	est sto m5`i'
        *build macro for coefplot
        loc cccccc `"`cccccc' (m5`i', aseq("2022m`i'")) "'
    loc `++i'		
}
di `"`cccccc'"'


#delimit ;
coefplot `cc' `ccc' `cccc' `ccccc' `cccccc', keep(treat)
yline(0) vertical legend(off)
graphregion(color(white))
ylabel(,nogrid) 
ytitle("Separation rate (T-C)") 
aseq swapnames
mcolor(black) msize(small)
ciopts(color(black)) 
xline(1 21 27 35 43, extend) 
xlabel(, angle(45) labsize(vsmall))
xtitle("Year-month")
text(0.04 1 "Pre-trial", place(e) size(vsmall) color(cranberry))
text(0.04 21 "Baseline", place(e) size(vsmall) color(cranberry))
text(0.04 27 "COVID-19", place(e) size(vsmall) color(cranberry))
text(0.04 35 "Implementation", place(e) size(vsmall) color(cranberry))
text(0.04 43 "Post-trial", place(e) size(vsmall) color(cranberry))
title("Panel B: Estimated Treatment Effects on Separation Rate (weighted by Headquarters Share)", size(medsmall))
;
#delimit cr
gr save "$path1/Figure3b.gph", replace 			

**Panel A: raw trends by treatment status

collapse seprate_prepost share, by(treat monyear)

#delimit ;
tw connected seprate_prepost monyear if treat==0 [pw=1/share], msize(small) || 
connected seprate_prepost monyear if treat==1 [pw=1/share], msize(small) || , 
graphregion(color(white))
ylabel(0 (0.01) 0.03,nogrid) 
ytitle("Separation rate") 
xlabel(, angle(45) labsize(vsmall))
xline(696 716 722 730 738, extend) 
xlabel(696(1)746, angle(45) labsize(vsmall))
xtitle("Year-month")
text(0.03 696 "Pre-trial", place(e) size(small) color(cranberry))
text(0.03 716 "Baseline", place(e) size(vsmall) color(cranberry))
text(0.03 722 "COVID-19", place(e) size(vsmall) color(cranberry))
text(0.03 730 "Implementation", place(e) size(vsmall) color(cranberry))
text(0.03 738 "Post-trial", place(e) size(vsmall) color(cranberry))
legend(order(1 "Control" 2 "Treatment"))
title("Panel A: Raw Trends in Separation Rate by Treatment Status (weighted by Headquarters Share)", size(medsmall))
;
#delimit cr
gr save "$path1/Figure3a.gph", replace 

#delimit ;	
gr combine "$path1/Figure3a.gph" "$path1/Figure3b.gph", cols (1)
graphregion(color(white))
; 
#delimit cr

graph export "$path1/Figure3.png", replace 

restore 































